package com.hdq.controller.admin;

import com.hdq.result.PageResult;
import com.hdq.result.Result;
import com.hdq.service.ImageClassService;
import dto.*;
import entity.ImageClass;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import vo.ImageClassAddVO;
import vo.ImageSelectVO;

import java.util.List;

@RestController
@RequestMapping("/admin/image_class")
@Tag(name = "图库分类管理")
@Slf4j
public class ImageClassController {


    @Autowired
    private ImageClassService imageClassService;

    @PostMapping
    @Operation(summary = "新增图库分类")
    public Result<ImageClassAddVO> addPictureCategroy(@RequestBody ImageClassAddDTO imageClassAddDTO) {
        ImageClass imageClass = imageClassService.insert(imageClassAddDTO);
        ImageClassAddVO imageClassAddVO = new ImageClassAddVO();
        BeanUtils.copyProperties(imageClass, imageClassAddVO);
        return Result.success(imageClassAddVO);
    }

    @DeleteMapping("/{id}")
    @Operation(summary = "删除图片分类")
    public Result deleteImageCategory(@PathVariable Integer id) {
        imageClassService.deleteImageCategory(id);
        return Result.success();
    }

    @PutMapping
    @Operation(summary = "修改图库分类")
    public Result update(@RequestBody ImageClassEditDTO imageClassEditDTO) {
        imageClassService.update(imageClassEditDTO);
        return Result.success();
    }

    @GetMapping("/{page}")
    @Operation(summary = "图库分类分页查询")
    public Result<PageResult> selectPictureCategoryByPage(@PathVariable Integer page, @RequestParam Integer limit) {
        PageResult pageResult = imageClassService.selectPictureCategoryByPage(page, limit);
        return Result.success(pageResult);
    }

    @GetMapping
    @Operation(summary = "图库分类查询")
    public Result<List<ImageClass>> selectPictureCategory() {
        List<ImageClass> imageClassList = imageClassService.selectPictureCategory();
        return Result.success(imageClassList);
    }















}
